﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="Maticsoft.Web.Register" %>

<%@ Register Src="Header3.ascx" TagName="Header3" TagPrefix="uc1" %>
<%@ Register Src="footer2.ascx" TagName="footer2" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="/img/icon.png" rel="icon" type="images/png" sizes="16*16" />
    <title>注册</title>
    <link rel="stylesheet" href="css/reset.css" />
    <link rel="stylesheet" href="css/common.css" />
    <link rel="stylesheet" href="css/login-register.css" />
    <script src="js/jquery.1.4.2-min.js" type="text/javascript"></script>
    <script src="js/layer/layer.js" type="text/javascript"></script>
    <script type="text/javascript">
        function refresh() {
            document.getElementById("authImg").src = 'ValidateCode2.aspx?now=' + new Date();
        }
        function Send() {
            if ($("#btnSendMsg").attr("flag") == "hong") {
                $.ajax({
                    type: "get",
                    url: "ashx/sendmsg.ashx",
                    data: "op=reg&mobile=" + $("#txtMobile").val() + "&verifycode=" + $("#txtVerifyCode").val() + "&d=" + new Date().toString(),
                    success: function (data) {
                        if (data == "1") {
                            $("#btnSendMsg").css("background-color", "#b9b9b9");
                            $("#btnSendMsg").attr("flag", "hui");
                            $("#num").text("60");
                            timer = setInterval("CountDown()", 1000);
                        }
                        else if (data == "-1") {
                            alert("手机格式错误");
                        }
                        else if (data == "-2") {
                            alert("短信发送失败，请重试");
                        }
                        else if (data == "-3") {
                            alert("该手机号已经注册");
                        }
                        else if (data == "-4") {
                            alert("验证码错误");
                        }
                    },
                    error: function (data) {
                        alert(data);
                    }
                })
                
            }
        }

        var timer = null;

        function CountDown() {
            var now = $("#num").text();
            if (now > 0) {
                now = now - 1;
                $("#num").text(now);
            }
            else {
                clearInterval(timer);
                $("#num").text("");
                $("#btnSendMsg").css("background-color", "#e4393c");
                $("#btnSendMsg").attr("flag", "hong");
            }
        }

        function Reg() {
            if ($("txtMobile").val() == "") {
                alert("请输入手机号");
                return false;
            }
            if ($("#txtCode").val() == "") {
                alert("请输入验证码");
                return false;
            }
            if ($("#txtPwd").val() == "") {
                alert("请输入密码");
                return false;
            }
            if ($("#txtPwd").val().length < 6) {
                alert("请至少输入六个字符密码");
                return false;
            }
            if ($("#txtPwd").val() != $("#txtPwd2").val()) {
                alert("两次输入密码不一致");
                return false;
            }
            if ($("input:checked").length == 0) {
                alert("请选择同意条款");
                return false;
            }
            $.ajax({
                type: "get",
                url: "register.aspx",
                data: "sync=true&ope=reg&username=" + $("#txtMobile").val() + "&pwd=" + $("#txtPwd").val() + "&code=" + $("#txtCode").val() + "&d=" + new Date().toString(),
                success: function (data) {
                    if (data == "1") {
                        window.location.href = "default.aspx";
                    }
                    else if (data == "-1") {
                        alert("验证码错误");
                    }
                    else if (data == "-2") {
                        alert("验证码超时");
                    }
                    else if (data == "-3") {
                        alert("名称重复");
                    }
                    else {
                        alert("注册失败");
                    }
                },
                error: function (data) {
                    alert(data);
                }
            })
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <uc1:Header3 ID="Header31" runat="server" />
    <div class="row bg-garay" style="padding: 30px 0;">
        <div class="safe_width bg-white" style="overflow: hidden;">
            <div class="regibox">
                <div class="row">
                    <p class="login-tit fl">
                        会员注册</p>
                    <a href="Login.aspx" class="fr fs-14 tc-red line-hei-30">点击登录</a> 
                    <div class="inputbox">
                        <input type="text" value="手机号" runat="server" id="txtMobile" onclick="if(this.value=='手机号'){this.value='';}" />
                    </div>
                    <div class="inputbox code">
                        <input type="text" value="验证码" class="codebox" runat="server" id="txtVerifyCode" onclick="this.value=''" />
                        <img
                        id="authImg" align="absmiddle" onclick="refresh()" style="cursor: pointer;"
                        alt="看不清？点击更换" src="ValidateCode2.aspx" />
                    </div>
                    <div class="inputbox code">
                        <input type="text" value="短信验证码" class="codebox" runat="server" id="txtCode" onclick="this.value=''" />
                        <button class="codebtn" flag="hong"  style="background-color: #e4393c;" type="button" id="btnSendMsg" onclick="Send();">
                            获取验证码 <span id="num"></span></button>
                    </div>
                    <div class="inputbox">
                        <input type="text" value="设置密码" runat="server" id="txtPwd_" onclick="$('#txtPwd_').hide();$('#txtPwd').show();$('#txtPwd').focus();" /><input type="password" runat="server" id="txtPwd" style="display:none" />
                    </div>
                    <div class="inputbox">
                        <input type="text" value="确认密码" runat="server" id="txtPwd2_" onclick="$('#txtPwd2_').hide();$('#txtPwd2').show();$('#txtPwd2').focus();" /><input type="password" runat="server" id="txtPwd2" style="display:none" />
                    </div>
                    <div class="row line-hei-20 tl fs-14 tc-black">
                        <input type="checkbox" runat="server" id="cbAgree" />我已阅读并同意牛顿屋 <span class="tc-blue" onclick="window.location.href='Detail.aspx?cid=10'" style="cursor:pointer">《服务协议》 </span>
                    </div>
                    <div class="row">
                        <input type="button" class="loginbtn" id="btnRegister" value="注 册" onclick="Reg();" />
                    </div>
                </div>
            </div>
        </div>
    </div>
    <uc2:footer2 ID="footer21" runat="server" />
    </form>
</body>
</html>
